package com.zircloud.tenant.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;

import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;

/**
 * @author test
 * @since 2022年1月10日
 */
@Configuration
@MapperScan("com.zircloud.**.mapper.**")
public class MybatisPlusConfig {

	/**
	 * 
	 */
	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
		interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
			@Override
			public Expression getTenantId() {
				Long tenantId = 1L;
				return new LongValue(tenantId);
			}

			@Override
			public boolean ignoreTable(String tableName) {
				return !"user_info".equalsIgnoreCase(tableName);
			}
		}));
		return interceptor;
	}
}
